package card;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;



public class CardMethod {

    private final String[] suits = {"♥", "♠", "♣", "♦"};


    // 买牌
    public List<Card> buyCard() {
        List<Card> cardList = new ArrayList<>();
        for (int i = 0 ; i < 4; i++) {
            for (int j = 1; j <= 13; j++) {
                Card card = new Card(suits[i], j);
                cardList.add(card);
            }
        }
        return cardList;
    }

    // 洗牌
    public void shuffle(List<Card> cardList) {
        Random random = new Random();
        for (int i = cardList.size() - 1; i > 0 ; i--) {
            int index = random.nextInt(i);
            // 交换
            swap(cardList, index, i);
        }
    }

    // 交换
    private void swap(List<Card> cardList, int index, int i) {
        Card temp = cardList.get(i);
        cardList.set(i,cardList.get(index));
        cardList.set(index, temp);
    }

    // 揭牌

    public void getCard(List<Card> cardList) {
        List<Card> hand1 = new ArrayList<>();
        List<Card> hand2 = new ArrayList<>();
        List<Card> hand3 = new ArrayList<>();

        List<List<Card>> people = new ArrayList<>();
        people.add(hand1);
        people.add(hand2);
        people.add(hand3);

        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < people.size(); j++) {
                Card card = cardList.remove(0);
                people.get(j).add(card);
            }
        }

        System.out.println("第1个揭牌如下：");
        System.out.println(hand1);
        System.out.println("第2个揭牌如下：");
        System.out.println(hand2);
        System.out.println("第3个揭牌如下：");
        System.out.println(hand3);

        System.out.println("剩下的牌：");
        System.out.println(cardList);



    }

}
